<?php

//系统设置模型
class System_model extends Model {

	function System_model()
	{
		parent::Model();	
		$this->load->database();
	}
	
	//更新敏感词过滤
	function filter($words)
	{
		if(trim($words) == "") return false;
		$words = explode(",",str_replace("，",",",$words));
		//清除原来filter
		$this->db->truncate("filter");
		//插入数据
		foreach ($words as $word) {
			if(trim($word) != "") {
				$data = array(
					"word" => trim($word),
				);
				$this->db->insert("filter", $data);
			}
		}
		return true;
	}
	
	//获取敏感词过滤
	function get_filter()
	{
		$words = "";
		$query = $this->db->get("filter");
		if ($query->num_rows()>0) {
			$result = $query->result_array();
			foreach ($result as $row) {
				$words[] = $row["word"];
			}
			$words = implode(",", $words);
		}
		return $words;
	}
	
	//获取敏感词过滤正则规则
	// /[|]/
	function get_filter_pattern()
	{
		$words = $pattern = "";
		$query = $this->db->get("filter");
		if ($query->num_rows()>0) {
			$result = $query->result_array();
			foreach ($result as $row) {
				$words[] = $row["word"];
			}
			$words = implode("|", $words);
			$pattern = '/('.$words.')/';
		}
		return $pattern;
	}
	
}

/* End of file */